package mips.instructions;

/**
 * <code>SLL</code> instruction<br/>
 * Shift Left Logical<br/>
 * @author jnmartin84@gmail.com
 */
public class SLL extends Instruction {

	private static final SLL INSTANCE = new SLL();
	private static final String INSTRUCTION_NAME = "SLL";

	private SLL(){}

	public static final SLL getInstance() {
		return INSTANCE;
	}

	/**
	 *
	 */
	@Override
	public final void execute(final int instruction) {

		final int rt = (instruction >> 16) & 0x0000001F;
		final int rd = (instruction >> 11) & 0x0000001F;
		final int sa = (instruction >> 6) & 0x0000001F;

		mips.R4300i.GPR[rd] = mips.R4300i.GPR[rt] << sa;
		
		mips.R4300i.PC = mips.R4300i.nPC;
		mips.R4300i.nPC = mips.R4300i.PC + 4;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String emit(final int instruction) {

		final int rt = (instruction >> 16) & 0x0000001F;
		final int rd = (instruction >> 11) & 0x0000001F;
		final int sa = (instruction >> 6) & 0x0000001F;

		return 	/*"		rt = ("+instruction+" >> 16) & 0x0000001F;\n" + 
				"		rd = ("+instruction+" >> 11) & 0x0000001F;\n" + 
				"		sa = ("+instruction+" >> 6) & 0x0000001F;\n" + 
				"		\n" +*/ 
				"		mips.CPU.GPR["+rd+"] = mips.CPU.GPR["+rt+"] << " + sa + ";" +
				"		\n" + 				
				"		mips.CPU.PC = mips.CPU.nPC;\n" + 
				"		mips.CPU.nPC = mips.CPU.PC + 4;\n";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String getName(final int instruction) {
		return getName();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String getName() {
		return INSTRUCTION_NAME;
	}
}